package com.fsh.subject.domain.handler.subject;

import com.fsh.subject.common.enums.IsDeletedFlagEnum;
import com.fsh.subject.common.enums.SubjectInfoTypeEnum;
import com.fsh.subject.domain.convert.BriefSubjectConverter;
import com.fsh.subject.domain.convert.JudgeSubjectConverter;
import com.fsh.subject.domain.entity.SubjectAnswerBO;
import com.fsh.subject.domain.entity.SubjectInfoBO;
import com.fsh.subject.domain.entity.SubjectOptionBO;
import com.fsh.subject.infra.basic.entity.SubjectBrief;
import com.fsh.subject.infra.basic.entity.SubjectJudge;
import com.fsh.subject.infra.basic.service.SubjectBriefService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 简答题目的策略类
 *
 * @author: ChickenWing
 * @date: 2023/10/5
 */
@Component
public class BriefTypeHandler implements SubjectTypeHandler{

    @Resource
    private SubjectBriefService subjectBriefService;

    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        SubjectBrief subjectBrief = BriefSubjectConverter.INSTANCE.convertBOToBrief(subjectInfoBO);
        subjectBrief.setSubjectId(subjectInfoBO.getId().intValue());
        subjectBrief.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        subjectBriefService.insert(subjectBrief);
    }

    /**
     * 查询 简答题
     *
     * @param subjectId 主题编号
     * @return {@link SubjectOptionBO }
     */
    @Override
    public SubjectOptionBO query(Long subjectId) {

        //查询  简答表
        SubjectBrief subjectBrief=new SubjectBrief();
        subjectBrief.setSubjectId(subjectId.intValue());
        subjectBrief.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
        SubjectBrief brief = subjectBriefService.queryByCondition(subjectBrief);
        //构造对象
        SubjectOptionBO subjectOptionBO=new SubjectOptionBO();
        subjectOptionBO.setSubjectAnswer(brief.getSubjectAnswer());

        return subjectOptionBO;
    }
}
